﻿$(document).ready(function() {
		liu.getshops('A946DBEE-51C9-4A97-A0BB-42EF31B3E029', 'SC', 'getShops', "{}", 2)
});

var liu = {
    flag: false,
    type: 2,
    staff: '',
    room: '',
    feature: '',
    getshops: function(id, lan, command, parameter, type, flag) {
        var datas = {
            "code": "{pid:'" + id + "',lan:'" + lan + "',command:'" + command + "',parameter:" + JSON.stringify(parameter) + "}"
        }
        if (type == 1) {
            var arr1 = JSON.parse(localStorage.getItem('staff'))
            if (arr1 != '' && arr1 != null) {
                liu.staff = arr1
            } else {
                object.getServeData(datas, function(data) {
                    if (data.c == 200 && data.v.length > 0) {
                        liu.staff = data.v
                        
                        data.v.forEach((e)=>{
                        	if(e.Floor == "25L"){
                        		arr1.push(e)
                        	}
                        })
                        liu.staff = arr1
                        if (flag) {
                            showArrAction(type, arr1)
                        }
                        localStorage.setItem('staff', JSON.stringify(liu.staff))
                    } else {
                        console.log("获取信息错误!");
                    }
                });
            }
        } else if (type == 2) {
            var arr1 = JSON.parse(localStorage.getItem('room'))
            if (arr1 != '' && arr1 != null) {
                liu.room = arr1
                if (flag) {
                    showArrAction(type, arr1)
                }
            } else {
                arr1 = []
                object.getServeData(datas, function(data) {
                    if (data.c == 200 && data.v.length > 0) {
                        data.v.forEach((e) => {
                            if (e.FloorID=="FFB6CB4B-AB5B-425A-BA96-51FB215FEEE4"&&(e.ShopID == "D216CFA3-E653-44D5-B1C3-AFDE829AF153" || e.ShopID == "6ED4FECC-77B1-430F-B13D-7AB2EF388D71" || e.ShopID == "2077CCA3-85E2-41AF-9E6A-4F3ABA657AEE" || e.ShopID == "0C2F062D-197C-446A-A95A-9BA40A982AE6" || e.ShopID == "D655441C-3157-4E12-B567-F3A4BE373508")) {
                                arr1.push(e)
                            }
                        })
                        liu.room = arr1
                        if (flag) {
                            showArrAction(type, arr1)
                        }

                        localStorage.setItem('room', JSON.stringify(arr1))
                    } else {
                        console.log("获取信息错误!");
                    }
                });

            }
        }
    }
}

function getlist(type, span) {
    $('.shares').hide()
    $(span).css({
        'color': '#006cb6'
    }).siblings().css({
        color: '#777'
    })
    if (type == 1) {
        liu.type = 1
        liu.getshops('A946DBEE-51C9-4A97-A0BB-42EF31B3E029', 'SC', 'SearchStaffSeatInfoByWhere', "{'key':'123'}", type)
        $('.nav_fj,.nav_yg,.nav_gn').hide()
        $('.yg_tishi').show().fadeOut(5000)
        $('.lost').html('无历史搜索记录')
    } else if (type == 2) {
        liu.type = 2
        $('.yg_tishi,.nav_yg,.nav_gn').hide()
        guolu('25', liu.room, 2)
        $('.lost').html('无历史搜索记录')
        $('.nav_fj').show()
        liu.getshops('A946DBEE-51C9-4A97-A0BB-42EF31B3E029', 'SC', 'getShops', "{}", type, true)
    } else if (type == 3) {
        liu.type = 3

        $('.yg_tishi,.nav_yg,.nav_fj').hide()
        guolu('25', object.feature, 3)
        $('.lost').html('无历史搜索记录')
    }

}

function showArrAction(type, list, floorName) {
    $('.nav_fj').empty();
    var htmlS = "";
    var htmlE = "";
    var li = ""
    var ul = $(".swiper-container3")
    if (type == 1) {
        var htmlS = '<ul class="swiper-wrapper swiper-wrapper3" style="flex-direction: column;">';
        var htmlE = '</ul>';
        for (var i = 0; i < list.length; i++) {
            li += '<li  class="searchPoint clearfix swiper-slide swiper-slide3" onclick=setPoint("' + list[i].RoomNo + '",1)>' +
                '<div class="left">' +
                '<img style="position: relative;left:.66rem;top: 0.23rem;width: 0.23rem;" src="images/' + list[i].Sex + '.png" alt=""><p class="pointName" style="font-size: 16px;position: relative;left: 53px;top: -11px;">' + list[i].EnName + '</p>' +
                '<p class="pointFloor" style="font-size:12px"><label style="position: relative;top: -0.7rem;left: 1rem;">' + list[i].CnName + '</label><label style="position: absolute;top: 0.25rem;left: 6.5rem;">' + list[i].Floor + '</label></p>' +
                '</div>' +
                '</li>'
        }
    }
    if (type == 2) {
        var htmlS = '<ul class="swiper-wrapper swiper-wrapper3" style="flex-direction: column;">';
        var htmlE = '</ul>';
        for (var i = 0; i < list.length; i++) {

            li += '<li  class="searchPoint clearfix swiper-slide swiper-slide3" onclick=setPoint("' + list[i].AreaID + '",2)>' +
                '<div class="left">' +
                '<img style="position: relative;left:.66rem;top: 0.3rem;width: 0.3rem;" src="images/' + list[i].FirstLetter + '.png" alt=""><p class="pointName" style="font-size: 16px;position: relative;left: 56px;top: -5px;">' + list[i].Name + '</p>' +
                '<p class="pointFloor" style="font-size:12px"><label style="position: absolute;top: 0.22rem;left: 6.1rem;">' + list[i].AreaName + '</label></p>' +
                '</div>' +
                '</li>'
        }
    }
    if (type == 3) {
        var htmlS = '<ul class="swiper-wrapper swiper-wrapper3" style="flex-direction: column;">';
        var htmlE = '</ul>';
        for (var i = 0; i < list.length; i++) {
            li += '<li  class="searchPoint clearfix swiper-slide swiper-slide3" onclick=setPoint("' + list[i].AreaID + '",2)>' +
                '<div class="left">' +
                '<img style="position: relative;left: .6rem;top: 0.3rem;width: 0.35rem;" src="images/' + list[i].Code + '.png" alt=""><p class="pointName" style="font-size: 0.3rem;position: relative;left: 1.12rem;top:-0.13rem">' + list[i].AreaTypeName + '</p>' +
                '<p class="pointFloor" style="font-size:.26rem"><label style="position: absolute;top: 0.2rem;left: 6.5rem;">' + floorName + '</label></p>' +
                '</div>' +
                '</li>'
        }
    }
	if (li.length < 1) {
        $(".yg_tishi").show()
        $(".yg_tishi span").hide()
        $(".yg_tishi div").html("没有当前位置，请重新搜索")
    }
    $('.nav_fj').append(htmlS + li + htmlE);
    $('.nav_fj,.nav_zz').show();
    $('.nav_qyfg').show()
	if ($("#text").val() == '') {
        $(".yg_tishi").hide()
        $(".yg_tishi span").show()
        $(".yg_tishi div").html("")
    }

}

$('#text').on('input', function() {
    $('.yg_tishi').hide()
    var str = $(this).val().toLowerCase()
    if (liu.type == 1) {
        $('.nav_yg').hide()
        guolu(str, liu.staff, 1)
    } else if (liu.type == 2) {
        guolu(str, liu.room, 2)
    } else if (liu.type == 3) {
        $('.nav_gn,.nav_zz').show()
        guolu(str, object.feature, 3)
        $('.nav_gn,.nav_zz').hide()
    }
})
$('#text').on('focus', function() {
    if (liu.type == 1) {
        $('.nav_yg').show()
        $('.yg_tishi,.nav_fj,.nav_gn').hide()
    } else if (liu.type == 2) {

    } else if (liu.type == 3) {
        $('.nav_fj').hide()
        $('.nav_gn,.nav_zz').show()
        $('.lost').html('无历史搜索记录')
    }
    $('.shares').hide()
});
$('#text').on('blur', function() {
})


function guolu(str, list, type) {
    var arr = []
    if (type == 1) {
        var nameStr;
        var nameStrc;
        var roomnoStr;
        for (var i = 0; i < list.length; i++) {
            nameStr = list[i].EnName
            nameStrc = list[i].CnName
            roomnoStr = list[i].RoomNo
            nameStr = nameStr.toLowerCase()
            if ((nameStr.indexOf(str) != -1 || nameStrc.indexOf(str) != -1 || roomnoStr.indexOf(str) != -1) && str != "" && str != undefined) {
                arr.push(list[i])
            }
        }
        showArrAction(type, arr)
    } else {
        if (type == 2) {
            var nameStr;
            for (var i = 0; i < list.length; i++) {
                nameStr = list[i].AreaName.toLowerCase()
                if (nameStr.indexOf(str) != -1 && str != "" && str != undefined) {
                    arr.push(list[i])
                }
            }
            showArrAction(type, arr)
        } else if (type == 3) {
            var nameStr
            var firstName
            for (var i = 0; i < list.length; i++) {
                nameStr = list[i].Name.toLowerCase()
                if (nameStr.indexOf(str) != -1 && str != "" && str != undefined) {
                    list[i].Area.forEach((e) => {
                        if ((e.Code == "shop"&&e.ShopName !=="会议室"&&e.ShopName !=="办公区"&&e.ShopName !=="休息区") || e.Code == "copy room" || e.Code == "Tea room" || e.Code == "Basketball" || e.Code == "man toilets" || e.Code == "woman toilets" || e.Code == "Escalator") {
                            arr.push(e)
                        }
                    })
                    firstName = list[i].Name;
                    break;
                }
            }
            showArrAction(type, arr, firstName)

        }

    }

}


var htmlS = '<ul class="swiper-wrapper swiper-wrapper3 nav_qj" style="flex-direction: column;">';
var htmlE = '</ul>';
$('#startPoint,#endPoint').on('input', function() {
    var str = $(this).val().toLowerCase()
    var list = []
    object.feature.forEach(($e, $index) => {
    	try {
    		if($e.Name.slice(0,2)!=25){
    			foreach.break=new Error("StopIteration")
    		}else {
    			$e.Area.forEach(el => {
                try {
                    if (str != '' && str != null &&(el.Name.indexOf(str) != -1||el.ShopName.indexOf(str) != -1 )&& el.Code == 'shop') {
                        var area = {}
                        area.floorName = $e.Name;
                        area.Area = el
                        list.push(area)
						
                    }
                }catch(e){
	
                }
                
          
        		})
    		}
    		 
    	}catch(e){
  		console.log(e)
    	}
    })
    var li = ""
    if (list.length > 0) {
        $('.nav_qj').show().html(' ')
        for (var i = 0; i < list.length; i++) {
            if (i < 40) {
                li = li + '<li  class="searchPoint clearfix swiper-slide swiper-slide3" onclick=setPoint("' + list[i].Area.AreaID + '",2)>' +
                    '<div class="left">' +
                    '<img style="position: relative;left: .6rem;top: 0.3rem;width: 0.35rem;" src="images/' + list[i].Area.Code + '.png" alt=""><p class="pointName" style="font-size: 0.3rem;position: relative;left: 1.12rem;top:-0.13rem">' + list[i].Area.ShopName + '</p>' +
                    '<p class="pointFloor" style="font-size:.26rem"><label style="position: absolute;top: 0.2rem;left: 6.5rem;">' + list[i].floorName + '</label></p>' +
                    '</div>' +
                    '</li>'
            }
        }
        $('.nav_qj').append(htmlS + li + htmlE);
    }


})


function searchHtmlS() {
    object.isStart = true;
	isPosition = false;
    if ($(this).id == startPoint) {
        console.log("asd")
    }
}

function searchHtmlE() {
    object.isEnd = true;
    if ($(this).id == startPoint) {
        console.log("asd")
    }
}
